<?php
session_start();
// if(!isset($_SESSION['title'])){
// 	die("<script>alert('未登录');window.location.href='login.php';</script>");
// }
include("../conn.php");
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
	$title = $_POST['title'];
	$content = $_POST['content'];
	     $sql = "insert into articles(title,content) values(:title,:content)";
	     $pdo = getConn();
	     $stmt = $pdo ->prepare($sql);
	     
	     $stmt->bindParam(":title",$title);
	     $stmt->bindParam(":content",$content);
	     $stmt->execute();
		 if($stmt->rowCount()>0){
				header("Location:list.php");
		 		 die("添加成功"); 
		 }else{
		 		 die("添加失败");
		 }
}
?>
<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title></title>
</head>
<body>
	<form action="" method="post">
		<div>文章标题：</div>
		<div><input type="text" name="title"></div>
		<div>文章内容：</div>
		<textarea name="content" hidden="hidden" id="content" cols="30" rows="10"></textarea>
		<div id="editor"></div>
		<input type="submit" value="添加">
	</form>
	<script src="https://unpkg.com/wangeditor/dist/wangEditor.min.js"></script>
	<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
	
	<script>
		const editor = new window.wangEditor("#editor");
		const content = $('#content')
		editor.config.onchange = function (html) {
		        // 第二步，监控变化，同步更新到 textarea
		        content.val(html)
		    }
		    editor.create();
	</script>
</body>
</html>